import random

class Role:
    huihe = 0
    buff = {1:"追加一层攻击增益",2:"扣除90%的生命值",3:"伤害翻倍",4:"攻击增益上限+1",5:"攻击增益上限+1",6:"追加一层攻击增益",7:"追加一层攻击增益"}
    def __init__(self,name,room):
        self.buff2 = []
        self.name = name
        self.attck = 10#基础伤害
        self.hp = 100
        self.room = room
        self.flag = 0 #伤害追加层数
        self.max = 6
        self.batk = 0

    def roll(self):
        print("生成随机buff中.........\n")
        num = random.randint(1, 7)
        print(f"{self.name}本回合的buff为{self.buff[num]}\n")
        self.buff2.append(num)
        self.add_buff(num)

    def statu(self,Role):
        if self.hp<=0:
            print(f"角色{self.name}死亡,游戏结束")
            return 1
        elif Role.hp<=0:
            print(f"角色{Role.name}死亡，游戏结束")
            return 1
        else:
            return 0

    def ttk(self, Role):
        print(f"由{self.name}发动攻击,对{Role.name}\n")
        print(f"{self.name}持有的buff：")
        for i in self.buff2:
            print(Role.buff[i])
        Role.hp-=self.attck
        print(f"本次攻击对{Role.name}造成{self.attck}点伤害\n")
        print(f"{Role.name}:{Role.hp}       vs        {self.name}:{self.hp}\n")
        if self.statu(Role) == 1:
            return 1
        else:
            return 0

    def add_buff(self,roll):
        if self.flag == self.max:
            print("攻击增益已到达上限--扣除50%hp,清空该buff层数\n")
            self.hp -= self.hp * 0.50
            print(f"{self.name}剩余hp{self.hp}\n")
            self.flag=0
            self.attack -= self.batk
        else:
            print("-------本次随机buff---------\n")

        if roll == 1 or roll == 6 or roll == 7 or roll == 4:

            print("随机buff:增加一层攻击增益\n")
            print(f"攻击伤害追加30%,该增益目前已叠加{self.flag}层\n")
            print(f"目前本单位该增益上限为{self.max}达到则立即扣除hp\n")
            self.batk += self.attck * 0.20
            self.flag+=1
            self.attck+=self.attck * 0.20

        elif roll == 2:
            print("随机buff:扣除90%的生命值\n")
            self.hp-=self.hp*0.9

        elif roll == 3:
            self.attck=self.attck*2

        elif roll == 5:
            self.max+=1

class Room:
    def __init__(self,num,Role1,Role2):
        self.num = num
        self.Role1 = Role1
        self.Role2 = Role2
        btn = input("y开始游戏--------------\n")
        if btn == "y":
            self.flow()

    def flow(self):
        Role.huihe=0
        while 1:
                Role.huihe += 1
                print(f"现在是{self.Role1.name}的第{Role.huihe}回合\n")
                chioce = input("本回合是否选择随机buff加成 y or n:")
                if chioce == "y":
                    self.Role1.roll()
                if self.Role1.ttk(self.Role2) == 1:
                    break
                # if chioce == "y":
                #     self.Role1.roll()
                #     if self.Role1.ttk(self.Role2) == 1:
                #         break
                # else:
                #     if self.Role1.ttk(self.Role2) == 1:
                #         break

                print(f"现在是{self.Role2.name}的第{Role.huihe}回合\n")
                chioce = input("本回合是否选择随机buff加成 y or n:")
                if chioce == "y":
                    self.Role2.roll()
                #     if self.Role2.ttk(self.Role1) == 1:
                #         break
                # else:
                if self.Role2.ttk(self.Role1) == 1:
                    break

r1 = Role("张三", 112)
r2 = Role("李四", 112)
rs = Room(112,r1,r2)
